<template>
    <div>


        <div class="topRoom">
            <el-form ref="form" :model="form" label-width="120px">
                <el-form-item label="请输入ddl">
                    <el-input v-model="form.ddl" type="textarea" rows="10">
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">生成模板</el-button>
                    <el-button>Cancel</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div>
            <h1>
                <span>{{this.tableName}} result</span>
                <button @click="()=>exportZip(this.tableName)">一键压缩包</button>
            </h1>
            <ul>
                <li><a href="#controller">controller</a></li>
                <li><a href="#entity">entity</a></li>
                <li><a href="#service">service</a></li>
                <li><a href="#mapper">mapper</a></li>
                <li><a href="#vue-list">vue-list</a></li>
                <li><a href="#vue-modify">vue-modify</a></li>
            </ul>
            <div id="entity">
                <h3>entity <span style="padding-left: 10px;cursor: pointer"
                                 @click="()=>copytext(result.entity)">复制</span></h3>
                <pre style="background: #fcfaf2;padding: 10px;">
                    <xmp v-html="result.entity"></xmp>
                </pre>
            </div>
            <div id="mapper">
                <h3>mapper <span style="padding-left: 10px;cursor: pointer"
                                 @click="()=>copytext(result.mapper)">复制</span></h3>
                <pre style="background: #fcfaf2;padding: 10px;">
                      <xmp v-html="result.mapper"></xmp>
                </pre>
            </div>
            <div id="service">
                <h3>service <span style="padding-left: 10px;cursor: pointer"
                                  @click="()=>copytext(result.service)">复制</span></h3>
                <pre style="background: #fcfaf2;padding: 10px;">
                      <xmp v-html="result.service"></xmp>
                </pre>
            </div>
            <div>
                <h3>serviceImpl <span style="padding-left: 10px;cursor: pointer"
                                      @click="()=>copytext(result.serviceImpl)">复制</span></h3>
                <pre style="background: #fcfaf2;padding: 10px;">
                      <xmp v-html="result.serviceImpl"></xmp>
                </pre>
            </div>
            <div id="controller">
                <h3>controller <span style="padding-left: 10px;cursor: pointer"
                                     @click="()=>copytext(result.controller)">复制</span></h3>
                <pre style="background: #fcfaf2;padding: 10px;">
                      <xmp v-html="result.controller"></xmp>
                </pre>
            </div>
            <div id="vue-list">
                <h3>vuelist <span style="padding-left: 10px;cursor: pointer"
                                  @click="()=>copytext(result.vuelist)">复制</span></h3>
                <pre style="background: #fcfaf2;padding: 10px;">
                      <xmp v-html="result.vuelist"></xmp>
                </pre>
            </div>
            <div id="vue-modify">
                <h3>vuemodify <span style="padding-left: 10px;cursor: pointer"
                                    @click="()=>copytext(result.vuemodify)">复制</span></h3>
                <pre style="background: #fcfaf2;padding: 10px;">
                      <xmp v-html="result.vuemodify"></xmp>
                </pre>
            </div>
            <div>
                <h3>jsjson <span style="padding-left: 10px;cursor: pointer"
                                 @click="()=>copytext(result.json)">复制</span></h3>
                <pre style="background: #fcfaf2;padding: 10px;">
                      <xmp v-html="result.jsjson"></xmp>
                </pre>
            </div>
            <div>
                <h3>帮助</h3>
                <div>
                    utils
                    --Lodash
                    --R
                </div>
                <pre v-html="staticHtml">
                </pre>
            </div>
        </div>
    </div>
</template>
<script>
    import {copy2bang, createA, getUrlParamNative} from "../../utils/utils";

    const staticHtml = `
package com.example.demo.utils;

public class Lodash {
    public static boolean isNil(Object str) {
        if (str == null) {
            return true;
        }
        if ("".equals(str)) {
            return true;
        }
        return false;
    }
    public static boolean isNil(Integer str) {
        if (str == null) {
            return true;
        }
        if ("".equals(str)) {
            return true;
        }
        if(str==0){
            return true;
        }
        return false;
    }
}

====

     package com.example.demo.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 *
 * @author Mark sunlightcs@gmail.com
 */
public class R extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public R() {
        put("code", 0);
        put("msg", "success");
    }

    public static R error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
    }

    public static R error(String msg) {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.put("msg", msg);
        return r;
    }

    public static R ok(Map<String, Object> map) {
        R r = new R();
        r.putAll(map);
        return r;
    }

    public static R ok() {
        return new R();
    }

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}`
    export default {
        data() {
            return {
                jquery: window.$,
                document,
                tableName: "",
                result: {entity: ""},
                form: {
                    ddl: "",
                    name: '',
                    region: '',
                    date1: '',
                    date2: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: '',
                },
                staticHtml
            }
        },
        async mounted() {
            this.tableName = getUrlParamNative('table')
            var ddl = await this.getDDLByTableName()
            this.form.ddl = ddl
            this.onSubmit()
            document.title = "模板生成器"
        },
        methods: {
            exportZip(tableName){
                createA(`/databases/exportZip?tableName=${tableName}`)
            },
            async getDDLByTableName() {
                var ddl = await axios.post('/databases/getDDLByTableName', {table: this.tableName}).then(res => res.data)
                return ddl;
            },
            onSubmit() {
                axios.post("/databases/createTemplate", {ddl: this.form.ddl}).then(res => res.data).then(res => {
                    this.$data.result.entity = res.entity
                    this.$data.result.mapper = res.mapper
                    this.$data.result.service = res.service
                    this.$data.result.serviceImpl = res.serviceImpl
                    this.$data.result.controller = res.controller
                    this.$data.result.vuelist = res.vuelist
                    this.$data.result.vuemodify = res.vuemodify
                    this.$data.result.jsjson = res.jsjson
                })
            },
            copytext(str) {
                this.$message('复制成功')
                copy2bang(str)
            }
        }
    }

</script>